<template>
  <div style="padding: 6px;">
    <el-button class="mt_5" type="primary" size="mini" icon="el-icon-plus" @click="addModel">add</el-button>
    <el-table :data="modelObj.list" border style="width: 100%">
      <el-table-column label="ModelName" prop="modelname"></el-table-column>
      <el-table-column label="#" width="200">
        <template v-slot="scope">
          <el-button size="mini" type="primary" @click="editModel(scope.row.id)">edit</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination v-if="modelObj.total>sd.pageSize" class="center" background layout="total, prev, pager, next"
                   @current-change="loadModel" :total="modelObj.total"
                   :current-page.sync="sd.pageNum" :page-size="sd.pageSize">
    </el-pagination>
    <el-dialog :title="popupTitle" :visible.sync="entityDetailVisible" width="1160px">
      <scstepmodeldetail v-if="entityDetailVisible" :visible.sync="entityDetailVisible" :entityId="popupEntityId"></scstepmodeldetail>
    </el-dialog>
  </div>
</template>

<script>
import request from '@/utils/request'
import scstepmodeldetail from "./scstepmodeldetail";

export default {
  components: { scstepmodeldetail },
  data() {
    return {
      sd: {
        roleName : '',
        pageNum: 1,
        pageSize: 5
      },
      modelObj: {},

      entityDetailVisible : false,
      popupTitle : '',
      popupEntityId : 0,
    }
  },
  mounted() {
    this.loadModel()
    this.$EventBus.$on("modeladd", () => {
      this.sd.pageNum = 1;
      this.loadModel();
    });
    this.$EventBus.$on("modeledit", () => {
      this.loadModel();
    });
  },
  beforeDestroy() {
    this.$EventBus.$off("modeladd")
    this.$EventBus.$off("modeledit")
  },
  methods: {
    loadModel() {
      request({
        url: '/emp/stepmodel/pagemodel',
        data: this.sd
      }).then(res => {
        const { data } = res
        this.modelObj = data
      })
    },
    addModel(){
      this.popupEntityId = 0;
      this.popupTitle= "add product step model"
      this.entityDetailVisible= true
    },
    editModel(id){
      this.popupEntityId= id;
      this.popupTitle= "update product step model"
      this.entityDetailVisible= true
    },
  }
}
</script>
